﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace memcached
{
    public class Runner
    {
        private static readonly string nunit = System.Configuration.ConfigurationManager.AppSettings["nunit"];

        [STAThread]
        public static void Main()
        {
            AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);
            try
            {
                AppDomain.CurrentDomain.ExecuteAssembly(
                    System.IO.Path.Combine(nunit, "NUnit-x86.exe"),
                    null,
                    new string[] { System.Reflection.Assembly.GetExecutingAssembly().Location });
            }
            catch
            {
                new MemCacheMockTest().Run();
                new MemCacheTest().Run();
                new NCacheTest().Run();
                new TxCacheReadCommittedTest().Run();
                System.Diagnostics.Trace.WriteLine("All passed");
            }
        }

        private static System.Reflection.Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
        {
            int i = args.Name.IndexOf(",");
            string file = args.Name.Substring(0, i) + ".dll";
            var ass = System.Reflection.Assembly.LoadFrom(
                System.IO.Path.Combine(System.IO.Path.Combine(nunit, "lib"), file));
            System.Diagnostics.Debug.Assert(ass.FullName == args.Name);
            return ass;
        }
    }
}